<?php
include_once($_SERVER['DOCUMENT_ROOT']."/config.php");
include_once($gDOCUMENT_ROOT_SYSTEM.'include/dao/spoken_language.php');
include_once($gDOCUMENT_ROOT_SYSTEM.'include/dao/spoken_language_name_translation.php');
class spokenLanguageAction
{
	private $spoken_language;
	private $spoken_language_name_translation;
	function __construct()
	{
		$this->spoken_language = new spoken_language();
		$this->spoken_language_name_translation = new spoken_language_name_translation();
	}
	public function getSpokenLanguageIdAndName($tag='zh-Hans-CN')
	{
		try
		{
			$id_tag = $this->spoken_language->getIdAndTag();
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		
		try
		{
			$id_name = $this->spoken_language_name_translation->getIdAndName($tag);
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		foreach($id_tag as $id=>$one_tag)
		{
			$id_name[$id] = $id_name[$id]."[".$one_tag."]";
		}
		return $id_name;
	}

	public function getNameByIdSum($id_sum,$tag='zh-Hans-CN')
	{
		try
		{
			if(empty($id_sum))
			{
				return array();
			}
			$id_name = $this->spoken_language_name_translation->getIdAndName($tag);
			
		}
		catch(Exception $e)
		{
			//echo 'Message: ' .$e->getMessage();
			return false;
		}
		foreach($id_name as $id=>$one_name)
		{
			$a = $id_sum&$id;
			if($a!=0)
			{
				$name[] = $one_name;
			}
		}
		return $name;
	}
}

?>
